package com.mobileares.midp.widgets.client.button;

import com.google.gwt.event.dom.client.*;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;

/**
 * Created by IntelliJ IDEA.
 * User: Tom
 * Date: 2011-3-23
 * Time: 14:35:20
 * To change this template use File | Settings | File Templates.
 */
public class CButton extends Button {
    private String dependStyle = "";

    public CButton(String text) {
        super(text);
        setStyleName("button-cbutton");
        if (text.length() > 2) {
            dependStyle = "2";
        }
        addStyleDependentName("normal" + dependStyle);
        init();
    }

    private void init() {
        addMouseOverHandler(new MouseOverHandler() {
            public void onMouseOver(MouseOverEvent event) {
                removeStyleDependentName("normal");
                addStyleDependentName("over" + dependStyle);
            }
        });
        addMouseOutHandler(new MouseOutHandler() {
            public void onMouseOut(MouseOutEvent event) {
                removeStyleDependentName("over" + dependStyle);
                addStyleDependentName("normal" + dependStyle);

            }
        });
        addBlurHandler(new BlurHandler() {
            public void onBlur(BlurEvent event) {
                removeStyleDependentName("over" + dependStyle);
                addStyleDependentName("normal" + dependStyle);

            }
        });
    }

//    /**
//     * This method is called immediately after a widget becomes attached to the
//     * browser's document.
//     */
//    @Override
//    protected void onLoad() {
//        if (getOffsetWidth() > 50) {
//
////            Window.alert(getOffsetWidth()+"");
//        }
//        addStyleDependentName("normal" + dependStyle);
//
//    }

}
